;;;Place a block named BFLG near the end of a line. (flange, a pipe fitting part)
;;;
;;;	Author:
;;;		Henry C. Francis
;;;		425 N. Ashe St.
;;;		Southern Pines, NC 28387
;;;
;;;	All rights reserved.
;;;
;;;	Copyright: 8-6-00
;;;	   Edited: 8-6-00
;;;
(defun c:bflg ( / );ent end1 end2 dis1 dis2 curla ang inpt
  (if dimscl nil (load"dimscl"))
  (dimscl)
  (if c:svlayr nil (load"mklayr"))
  (c:svlayr)
  (setq oldosmode (getvar"osmode"))
  (setvar "osmode" 0)
  (while
    (setq ent (nentsel "\nSelect line for bend part "))
    (cond
      ((eq(cdr(assoc 0(entget (car ent))))"LINE")
        (setq pickpt (nth 1 ent))
        (setq pickpt (list(car pickpt)(cadr pickpt)))
        (setq end1 (cdr(assoc 10(entget (car ent)))))
        (setq end2 (cdr(assoc 11(entget (car ent)))))
        (setq end1 (list(car end1)(cadr end1)))
        (setq end2 (list(car end2)(cadr end2)))
        (setq dis1 (distance pickpt end1))
        (setq dis2 (distance pickpt end2))
        (setq curla (cdr(assoc 8(entget (car ent)))))
        (if (> dis1 dis2)
          (setq ang (angtos(angle end2 end1) 0 4)
                inpt end2)
          (setq ang (angtos(angle end1 end2) 0 4)
                inpt end1)
        );if
        (setvar "clayer" curla)
        (command ".insert" "bflg" inpt dimsc dimsc ang)
      );eq
      ((eq(cdr(assoc 0(entget (car ent))))"VERTEX")
        (setq end1 (cdr(assoc 10(entget(car ent)))))
        (setq next_ent (entget(entnext (car ent))))
        (if (eq(cdr(assoc 0 next_ent))"VERTEX")
          (progn
            (setq end2 (cdr(assoc 10 next_ent)))
            (setq pickpt (nth 1 ent))
            (setq pickpt (list(car pickpt)(cadr pickpt)))
            (setq end1 (list(car end1)(cadr end1)))
            (setq end2 (list(car end2)(cadr end2)))
            (setq dis1 (distance pickpt end1))
            (setq dis2 (distance pickpt end2))
            (setq curla (cdr(assoc 8(entget (car ent)))))
            (if (> dis1 dis2)
              (setq ang (angtos(angle end2 end1) 0 4)
                    inpt end2)
              (setq ang (angtos(angle end1 end2) 0 4)
                    inpt end1)
            );if
          );progn
        );if
        (setvar "clayer" curla)
        (command ".insert" "bflg" inpt dimsc dimsc ang)
      );eq
      (T(princ (cdr(assoc 0(entget(car ent))))))
    )
  );while
  (setvar "osmode" oldosmode)
  (c:rslayr)
  (PRINC)
);defun
